<template>
  <div id="retrievepwd">
    <div class="toptitle">
      <div class="left">
        <img src="../../../static/images/retrieve-logo.png" />
        <span>|</span>
        <h3>找回密码</h3>
      </div>
      <div class="right">
        <h3 @click='backlogin()' style='cursor: pointer;color:#2970CC'>登陆</h3>
      </div>
    </div>
    <div class="retrievewrap">
      <div class="retrieveitem phoneitem">
        <span>手机号码</span>
        <input class="phonenum" type="number" v-model="cellphone" placeholder="注册时使用的手机号" />
        <!--  @blur="phone_num($event)" -->
      </div>
      <div class="retrieveitem justy">
        <div class="leftinput">
          <span>短信验证码</span>
          <input class="code" type="text" placeholder="填写6位短信验证码" />
        </div>
        <div class="codebtn">
          <span v-show="show" @click="getCode">获取验证码</span>
          <span v-show="!show" class="count">{{count}} s</span>
        </div>
      </div>
      <div class="retrieveitem justy">
        <div class="leftinput">
          <span>设定新密码</span>
          <input class="newpwd" type="password" placeholder="6~20个字，包含字母和数字" />
        </div>
        <img src="../../../static/images/keyboard-icon.png" />
      </div>
      <div class="retrieveitem justy">
        <div class="leftinput">
          <span>确认新密码</span>
          <input class="confirmpwd" id="confirmpwd" type="password" placeholder="再次输入新密码" />
        </div>
        <img src="../../../static/images/keyboard-icon.png" />
      </div>
      <button @click="confirm">确认</button>
    </div>
    
    <!-- 小黑窗 -->
    <div class="modelwrap">
      <p>{{modelmsg}}</p>
    </div>
  </div>
</template>
<script>
export default {
  name: 'retrievepwd',
  data() {
    return {
      show: true,
      count: '',
      timer: null,
      modelmsg: '',
      cellphone: '', //手机号码
      stop:false,
    }
  },
  methods: {
    // 路由
    backlogin() {
      this.$router.go(-1);
    },
    // 获取验证码
    getCode() {
      var that = this;
      var cellphone = that.cellphone;
      var pattern =   /^(1[3-9])\d{9}$/; 
      if(that.stop){
        return false
      }
      that.stop=true;
      setTimeout(()=>{
        that.stop=false
      },2000)
      if (cellphone == '') {
        that.modelmsg = "手机号码不能为空";
        $('.modelwrap').fadeIn().delay(1500).fadeOut();
         return false;
      } else if (!pattern.test(cellphone)) {
        that.modelmsg = "手机号码错误";
        $('.modelwrap').fadeIn().delay(1500).fadeOut();
         return false;
      }
      that.$post({
        url: 'Common/Common/sendSms',
        data: { phone: cellphone },
        success: (data) => {
          if (data.code == 1000) {
            that.modelmsg = data.message;
            $('.modelwrap').fadeIn().delay(1500).fadeOut();
            // 跳转登录页面
 				that.cundrion();//倒计时方法
          } else {
            that.modelmsg = data.message;
            $('.modelwrap').fadeIn().delay(1500).fadeOut();
          }
        }
      })
    },
    //倒计时
    cundrion(){
    	var that=this;
        var TIME_COUNT = 120;
    if (!this.timer) {
      this.count = TIME_COUNT;
      this.show = false;
      this.timer = setInterval(() => {
        if (this.count > 0 && this.count <= TIME_COUNT) {
          this.count--;
        } else {
          this.show = true;
          clearInterval(this.timer);
          this.timer = null;
        }
      }, 1000)
    }
    },

    //确认
    confirm() {
      console.log('重写代码去吧!!!!!!!!!!!!!!!!!!!!!!')
      this.$alert('重写代码去吧,没有现成的')
      return fasle;
      var that = this;
      // ajax请求
      that.$post({
        url: 'Partner/User/retrievePassword',
        data: { },
        success: (data) => {
          if (data.code == 1000) {
            console.log('重写代码去吧')
          } else {
            this.modelmsg = data.message;
            $('.modelwrap').fadeIn().delay(1500).fadeOut();
          }
        }
      })
    }

  },
  mounted() {

  },
  created() {}
}

</script>
<style>
#retrievepwd {
  width: 1200px;
  margin: 0 auto;
}

#retrievepwd .toptitle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #d9d9d9;
  font-size: 24px;
  font-weight: bold;
  margin-top: 100px;
  padding-bottom: 10px;
}

#retrievepwd .toptitle .left {
  display: flex;
  align-items: center;
}

#retrievepwd .toptitle span {
  color: #d9d9d9;
  font-weight: normal;
  padding: 0 15px;
}

#retrievepwd .retrievewrap {
  margin-top: 80px;
}

#retrievepwd .retrieveitem {
  width: 400px;
  margin: 0 auto;
  padding: 15px 10px;
  border-bottom: 1px solid #d9d9d9;
  display: flex;
  align-items: center;
  margin-bottom: 37px;
}

#retrievepwd .retrieveitem span {
  font-size: 16px;
  font-weight: bold;
  width: 30%;
}

#retrievepwd .retrieveitem .leftinput span {
  margin-right: 36px;
}

#retrievepwd .retrieveitem input {
  border: none;
  font-size: 16px;
}

#retrievepwd .phoneitem {
  border-bottom: 2px solid #2970cc;
}

#retrievepwd .retrieveitem .codebtn span {
  cursor: pointer;
  font-size: 16px;
  color: #FF6565;
  font-weight: normal;
}

#retrievepwd .retrieveitem .codebtn .count {
  color: #d9d9d9;
  cursor: auto;
}

#retrievepwd .justy {
  justify-content: space-between;
}

#retrievepwd .retrieveitem img {
  width: 22px;
  height: 15px;
}

#retrievepwd .retrievewrap button {
  background-color: #2970cc;
  border-radius: 5px;
  border: none;
  color: #FFF;
  font-size: 18px;
  width: 420px;
  margin: 0 auto;
  display: block;
  height: 50px;
  cursor: pointer;
  margin-top: 70px;
}


#retrievepwd .modelwrap {
  width: 350px;
  height: 120px;
  border-radius: 5px;
  text-align: center;
  line-height: 120px;
  background-color: rgba(0, 0, 0, 0.7);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  color: #FFF;
  font-size: 18px;
  display: none;
}

#retrievepwd .modelwrap p {
  margin: 0;
}

</style>
